import request from '@/utils/request'
import { CommentAddReq, CommentTreeResp, MessageVo } from '@/api/comment/type'
import { PageDto } from '@/api/type'

const api = '/v1/comments'

/** 文章id查询评论 */
export const treeByArticleId = (id: any): Result<CommentTreeResp> => {
  return request({
    url: `${api}/comment/${id}`,
    method: 'get'
  })
}

/** 查询友链页面留言 */
export const listMessage = () => {
  return request({
    url: `${api}/link`,
    method: 'get'
  })
}

/** 新增评论 */
export const addComment = (data: CommentAddReq): Result<void> => {
  return request({
    url: `${api}/comment`,
    method: 'post',
    data
  })
}

/** 删除评论 */
export const deleteComment = (ids: any) => {
  return request({
    url: `/system/comment/${ids}`,
    method: 'delete'
  })
}

/** 点赞或者取消 */
export const clickLike = (id: number): Result<void> => {
  return request({
    url: `${api}/clickLike/${id}`,
    method: 'post'
  })
}

/** 点踩或者取消 */
export const clickDislike = (id: number) => {
  return request({
    url: `${api}/clickDislike/${id}`,
    method: 'post'
  })
}

/** 分页查询留言板留言 */
export const pageMessage = (params: PageQuery): Result<PageDto<MessageVo>> => {
  return request({
    url: `${api}/message/page`,
    method: 'get',
    params
  })
}
